
import 'package:flutter/material.dart';
import 'package:flutter_bmfmap_example/http/http.dart';
import 'package:flutter_bmfmap_example/pages/marketpage/componets/gooditemcard.dart';
import 'package:flutter_bmfmap_example/tool/HYSizeFit%20.dart';

class TestDemopage extends StatefulWidget {
  const TestDemopage({ Key key }) : super(key: key);

  @override
  _TestDemopageState createState() => _TestDemopageState();
}

class _TestDemopageState extends State<TestDemopage> {

  var absoluteAddress;

  @override
  initState() {
    super.initState();
    // 页面加载时调用 用来开始时访问数据库
    _getinfo();
  }

  _getinfo() async {
    var response = await Http.get(
        'http://xiangrikui.vaiwan.com/userAddress/getAbsoluteAddress');
    this.absoluteAddress = response;
    // print(this.absoluteAddress['name']);
    setState(() {});
  }
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('data'),
      ),
      body: Column(
        children:[
          Text('data'),
          _buildtop(),
          _buildbody(),
        ]
      ),
    );
  }

  _buildbody() {
    return Expanded(
      child: ListView(
        physics: const AlwaysScrollableScrollPhysics(
          parent: BouncingScrollPhysics(),
        ),
        children: [
          GooditemCard(commodityId: '1', num: '1',),
        ],
      ),
    );
  }

  _buildtop() {
    return Stack(
      children: [
        Container(
          height: 140,
          decoration: BoxDecoration(
            border: Border.all(color: Colors.grey[400], width: 0.5),
            borderRadius: BorderRadius.only(
              bottomLeft: Radius.circular(24),
              bottomRight: Radius.circular(24),
            ),
            gradient: LinearGradient(
              begin: Alignment.topLeft,
              end: Alignment.bottomRight,
              colors: [
                Color.fromRGBO(234, 204, 132, 1),
                Color.fromRGBO(217, 177, 90, 1)
              ],
            ),
          ),
        ),
        Column(
          children: [
            SizedBox(
              height: 40,
            ),
            Container(
              width: HYSizeFit.screenWidth,
              child: Stack(
                alignment: Alignment.center,
                children: [
                  Positioned(
                    left: 32,
                    child: InkWell(
                      onTap: () {
                        Navigator.pop(context);
                      },
                      child: Icon(
                        Icons.arrow_back_ios,
                        size: 16,
                        color: Colors.white,
                      ),
                    ),
                  ),
                  Container(
                    child: Text(
                      '确定订单',
                      style: TextStyle(
                          fontSize: 20,
                          fontWeight: FontWeight.w600,
                          color: Colors.white),
                    ),
                  ),
                ],
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(
                  left: 16.0, right: 16, top: 16, bottom: 16),
              child: Container(
                // height: 40,
                padding: const EdgeInsets.only(
                    left: 8.0, right: 8, top: 16, bottom: 16),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(12),
                ),
                child: Row(
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Container(
                              margin: EdgeInsets.only(right: 12),
                              child: Text(
                                this.absoluteAddress == null
                                    ? "---"
                                    : this.absoluteAddress['name'],
                                style: TextStyle(
                                  fontSize: 16,
                                  fontWeight: FontWeight.w600,
                                ),
                              ),
                            ),
                            Text(
                              this.absoluteAddress == null
                                  ? "---"
                                  : this.absoluteAddress['phone'].toString(),
                              style: TextStyle(
                                fontSize: 18,
                                height: 1.4,
                                fontWeight: FontWeight.w700,
                              ),
                            )
                          ],
                        ),
                        SizedBox(height: 8),
                        Row(
                          children: [
                            Container(
                              width: 232,
                              child: Text(
                                this.absoluteAddress == null
                                    ? "---"
                                    : this.absoluteAddress['province'] +
                                        ' ' +
                                        this.absoluteAddress['municipality'] +
                                        ' ' +
                                        this.absoluteAddress['district'] +
                                        ' ' +
                                        this.absoluteAddress['addressIntro'],
                                maxLines: 2,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                    fontSize: 13, color: Colors.black87),
                              ),
                            ),
                            // Spacer(),
                          ],
                        ),
                      ],
                    ),
                    Spacer(),
                    Container(
                      child: Icon(
                        Icons.keyboard_arrow_right_sharp,
                        color: Colors.grey[600],
                      ),
                      // onTap: () {
                      //   print('进入收货地址选择页面');
                      // },
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ],
    );
  }
}